$(function () {
	$('#shortener').submit(function () {
		$.ajax({
			type: "POST",
			url: 'shorten.php',
			data:{
				recaptcha_challenge_field: $('[name="recaptcha_challenge_field"]').val()  , 
				recaptcha_response_field: $('[name="recaptcha_response_field"]').val()  , 
				longurl: $('#longurl').val()
			},
			complete: function (XMLHttpRequest, textStatus) {
				Recaptcha.reload();
				if((XMLHttpRequest.responseText).search(/http/) != -1){
					$('span#eresponse').text('');
					$('span#response').text(XMLHttpRequest.responseText);
				}
				else{
					setTimeout("$('span#eresponse').text('');",4000);
					$('span#response').text('');
					$('span#eresponse').text(XMLHttpRequest.responseText);
				}
			}
		});
		return false;
	});
});
